﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Terminal.Advanced_AEUC_settings_controls.Settings_AUX;

namespace Terminal.Advanced_AEUC_settings_controls.Scripting
{
    /// <summary>
    /// Put script to sleep script action
    /// </summary>
    class ScrPwrCtrl : ScrBasicAction
    {
        /// <summary>
        /// Public constructor for the script action
        /// </summary>
        /// <param name="iDispName">Action display text</param>
        /// <param name="iUsageHelp">Usage help and comments text for the action</param>
        public ScrPwrCtrl(string iDispName, string iUsageHelp)
            : base(iDispName, iUsageHelp)
        {
            usageHelp += "Input params: Integer(0 = off, 1 = on, 2 = reset)\n";
        }

        /// <summary>
        /// Perform the action using specified parameters.
        /// </summary>
        /// <param name="paramList">List of the input/output parameters for the action</param>
        /// <returns>True if action is succesful</returns>
        public override bool Do(List<object> paramList)
        {
            if (breakPoint)
                WaitUserInput();

            if (paramList.Count > 0)
            {
                int connectStatus = (int)(paramList[0]);

                if (connectStatus == 0)
                    ComPowerSwitch.ComSwitch.PowerOff();
                else if (connectStatus == 1)
                    ComPowerSwitch.ComSwitch.PowerOn();
                else if (connectStatus == 2)
                    ComPowerSwitch.ComSwitch.Reset();
                else
                    return false;

                return true;
            }

            return false;
        }

        /// <summary>
        /// Generate C source code for specified parameters
        /// </summary>
        /// <param name="paramlist">List of input/output parameters for the action</param>
        /// <returns>C source string</returns>
        public override string GenerateSourceCode(List<object> paramList)
        {
            string c_source = "Can't generate source - check script file!";

            if (paramList.Count > 0)
            {
                int connectStatus = (int)(paramList[0]);
                if (connectStatus == 0)
                    c_source = "////Power on\n";
                else if (connectStatus == 1)
                    c_source = "////Power off\n";
                else if (connectStatus == 2)
                    c_source = "////Power reset\n";
            }

            return c_source;
        }

        /// <summary>
        /// Returns a List containing objects of the parameter list required for the Do function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamList()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(int));

            return paramList;
        }

        /// <summary>
        /// Returns a List containing objects of the parameter list required for the GenerateSourceCode function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamListSourceGen()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(int));

            return paramList;
        }
    }
}
